﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;

namespace Repo7.BusinessLogic.Local
{
    /// <summary>
    /// Class containing data about a file in the repository
    /// </summary>
    [Serializable]
    public class RepoFileInfo
    {
        #region Public Properties

        /// <summary>
        /// File Id
        /// </summary>
        public long Id;

        /// <summary>
        /// File Name
        /// </summary>
        public string Name;

        /// <summary>
        /// File path
        /// </summary>
        [NonSerialized]
        public string FullPath;

        /// <summary>
        /// File Size in bytes
        /// </summary>
        public long Size;

        /// <summary>
        /// File Hash
        /// </summary>
        public string Hash;

        /// <summary>
        /// File Version
        /// </summary>
        public long Version;

        /// <summary>
        /// Is file deleted
        /// </summary>
        public bool IsDeleted;

        #endregion

        #region Public Methods

        /// <summary>
        /// Get a JSON representation of the file Info
        /// </summary>
        /// <returns></returns>
        public string GetJson()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return serializer.Serialize(this);
        }

        /// <summary>
        /// Updates the current repository file info, excluding the Id
        /// </summary>
        /// <param name="newInfo"></param>
        /// <returns></returns>
        public void UpdateInfo(RepoFileInfo newInfo)
        {
            Name = newInfo.Name;
            FullPath = newInfo.FullPath;
            Size = newInfo.Size;
            Hash = newInfo.Hash;
            Version = newInfo.Version;
            IsDeleted = newInfo.IsDeleted;
        }

        #endregion
    }
}
